package com.junjun.ssm.controller;

import com.junjun.ssm.entity.MovieEntity;
import com.junjun.ssm.service.IMovieService;
import com.junjun.ssm.util.SnowIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("movieOne")
public class MovieController {


    @Autowired
    IMovieService movieService;



    @PostMapping("addMovie")
    public String addMovie(@RequestBody MovieEntity movieEntity) {
        String movieId = SnowIdUtils.uniqueLongHex();
        movieEntity.setMovieId(movieId);
        if (movieService.queryMovieByName(movieEntity.getMovieName()) == null) {
            movieService.addMovie(movieEntity);
        } else {
            MovieEntity movieEntity1 = movieService.queryMovieByName(movieEntity.getMovieName());
            movieEntity1.setMovieNum(movieEntity.getMovieNum() + movieEntity1.getMovieNum());
            movieService.addMovie(movieEntity1);
        }
        return "ok";
    }

    @PostMapping("queryAllMovie")
    public List<MovieEntity> queryAllMovie() {

      //  return movieService.queryAllMovie();
        return movieService.queryAllMovie();
    }

    @PostMapping("query")
    public String queryText() {

        return "测试：负载均衡8205";
    }


}
